

package PL.practica1;


import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;

import nu.xom.*;


public class XmlToHtml {


	public static void main(String[] args) throws Exception {

		FileInputStream fstream = new FileInputStream("invitation.xml");
		Builder builder = new Builder();  
		Document doc = builder.build(fstream);
		// Obtenemos la etiqueta raíz  
		Element raiz = doc.getRootElement(); 
		fstream.close();
		To to = new To();
		Date date = new Date();
		Where where = new Where();
		Why why = new Why();
		Par par = new Par();
		Signature signature = new Signature();
        crearInvitacion (raiz, 0, to, date, where,why, par, signature);
        
        Invitacion i = new Invitacion ();
		
		BufferedWriter out = new BufferedWriter (new FileWriter("invitacion.html"));
		i.translateInvitacion(out, to, date, where,why, par, signature);
		out.close();

	}
	
	
	public static void crearInvitacion(Node current, int depth, To to, Date date,
			Where where, Why why, Par par, Signature signature) {

//		printSpaces(depth);
		
		String etiqueta = "";
		if (current instanceof Element) {
			Element temp = (Element) current;
			etiqueta = temp.getQualifiedName(); 
 
			switch (etiqueta){
			case "to": to.setTo(temp.getValue()); break;
			case "date": date.setDate(temp.getValue()); break;
			case "where": where.setWhere(temp.getValue()); break;
			case "why": why.setWhy(temp.getValue()); break;
			case "emph": par.setPar(temp.getValue(), true); break;
			case "par": par.setPar(temp.getValue(), false); break;
			case "signature": signature.setSignature_(temp.getValue()); break;
			}

		}
		for (int i = 0; i < current.getChildCount(); i++){
			crearInvitacion(current.getChild(i), depth+1, to, date, where,why,par, signature);
		}

	}


	
	
	
}
